﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Contributor.Data_Objects;

namespace Contributor
{
    /// <summary>
    /// Interaction logic for ucLookupTable.xaml
    /// </summary>
    public partial class ucLookupTable : UserControl
    {
        public ucLookupTable()
        {
            InitializeComponent();
            this.Loaded += new RoutedEventHandler(ucLookupTable_Loaded);
        }

        void ucLookupTable_Loaded(object sender, RoutedEventArgs e)
        {
            if (AppConfig.LookupTypes == null) AppConfig.LookupTypes = LookupType.LoadLookupTypes();
            lbLookupType.ItemsSource = AppConfig.LookupTypes;
        }

        private void ListBoxEdit_SelectedIndexChanged(object sender, RoutedEventArgs e)
        {
            if (AppConfig.LookupTable == null) AppConfig.LookupTable = Lookup.LoadLookup();

            LookupType type = lbLookupType.SelectedItem as LookupType;
            if (type != null)
            {
                gridLookup.ItemsSource = from l in AppConfig.LookupTable where l.LookupTypeId==type.LookupTypeId select l;
            }
            else
            {
                gridLookup.ItemsSource = null;
            }

        
        }
    }
}
